package com.henu.adapter;

import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.henu.R;
import com.henu.xyh.entity.News;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.Collections;

/**
 * Created by xing on 2017/5/22.
 */

public class Listnewsadapter extends BaseAdapter {
    private ArrayList<News> newslist=new ArrayList<>();
    LayoutInflater inflater;
    public Listnewsadapter(Context context){
        inflater=LayoutInflater.from(context);
    }
    public void addData(ArrayList<News> templist)
    {
        newslist.clear();
        newslist.addAll(templist);
    }
    public int getCount() {
        return newslist.size();
    }

    @Override
    public News getItem(int i) {
        return newslist.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if(view==null)
        {
            view= inflater.inflate(R.layout.inflate_lv_news_item,null);
        }
        ImageView image= (ImageView) view.findViewById(R.id.new_image);
        TextView tilte= (TextView) view.findViewById(R.id.news_title);
        TextView time= (TextView) view.findViewById(R.id.news_time);
        News news=newslist.get(i);
        ImageLoader.getInstance().displayImage(news.getImage().getFileUrl(),image);
        tilte.setText(news.getTitle());
        time.setText(news.getPublishdate().getDate());
        return view;
    }
}
